package com.example;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.database.StudentMessage;
import com.example.entity.Student;
import com.example.view.Customize;

public class StudentInformationActivity extends AppCompatActivity {
    private StudentMessage studentMessage ;
    private Customize customize ;
    private TextView s_name ;
    private TextView s_id ;
    private TextView s_sex ;
    private TextView s_course ;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.student_information);
        customize = findViewById(R.id.studentDetails);
        s_name = findViewById(R.id.sName) ;
        s_id = findViewById(R.id.sId) ;
        s_sex = findViewById(R.id.sSex) ;
        s_course = findViewById(R.id.sCourse) ;
        studentMessage = new StudentMessage(this);

        customize.setTitleText("同学信息");
        customize.setRightBtnNoVisible(true);
        customize.setLeftBtnIsVisible(true);
        customize.setLeftBtnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        Intent intent = getIntent() ;
        String studentId = intent.getStringExtra("studentId") ;
        Log.d("TAG", "onCreate: "+studentId);
        Student student = studentMessage.getStudentById(studentId);
        if (student != null){
            s_name.setText("姓名：" + student.getStudentName());
            s_id.setText("学号：" + studentId);
            s_sex.setText("性别：" + student.getSex());
            s_course.setText("班级：" + student.getCourse());
        }else {
            Toast.makeText(this, "未找到学生信息", Toast.LENGTH_SHORT).show();
        }

    }
}
